home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 11 / FM Towns Free Software Collection 11.iso / t_os / lib / yotpin / src / tree.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-20  |  3.7 KB  |  187 lines

  1. /*
  2. *    Yamana's Otomeza Plug-in Tool
  3. *        木を植える
  4. *    
  5. *    1995.07.10  乙女座対応版
  6. *    1995.08.11  スタンプ化。タイルパターンも有効になるようにした
  7. *    1995.08.13  一気に処理速度を 60~70% 高速化した
  8. *    
  9. */
  10. #include    "otome_pi.h"
  11. #include    "costbl.h"
  12.  
  13. const char longname[]  = "STAMP : 木を植える";
  14. int            cnfg_max = 2;
  15. PI_CNFG        cnfg[] =
  16.             {    /* 1234567890123456 ,min,max,def,set */
  17.                 { "木の高さ → 高"    ,  2, 15,  6,  6 },
  18.                 { "幹の太さ → 太"    ,  2, 12,  6,  6 },
  19.             };
  20.  
  21. #define    USE_ENV     PI_SET_ENV
  22. #define    USE_PEN     PI_USER_PEN
  23.  
  24. #define     USE_TYPE    PI_DRAW_STAMP
  25.  
  26.     /* たぶんこれ以上にはならないはずなんだが? */
  27. POINT        stamp={ 320*2,480*2 };
  28.  
  29. #include    "otome_pi.c"
  30.  
  31.  
  32. /********************************/
  33.  
  34. void mk_treeLR(x,y,pen,len,arc)
  35. int     x,y,pen,len;
  36.  
  37. #ifdef USE_LIB
  38.     float    arc;
  39. #else
  40.     int     arc;
  41. #endif
  42.  
  43. {
  44.     int     x_L,y_L,x_R,y_R;
  45.     int     len_L,len_R;
  46. #ifdef USE_LIB
  47.     float    arc_L,arc_R;
  48. #else
  49.     int     arc_L,arc_R;
  50. #endif
  51.     struct
  52.     {    short    n;
  53.         short    x0,y0;
  54.         short    x1,y1;
  55.         short    x2,y2;
  56.     }tree;
  57.     
  58.     int     ch,mx,my;
  59.     
  60.     if( pen < 1 )    return;
  61.     MOS_rdpos( &ch, &mx, &my );
  62.     if( (ch & 3)== 0x02 )    return;
  63.     
  64.     srand( (unsigned int)clock() );
  65.     
  66.     /* 元の長さの 3/4 くらい... */
  67.     len_L = (6 + (rand() & 1)) * len / 8 ;
  68.     len_R = (6 + (rand() & 1)) * len / 8 ;
  69.     
  70. #ifdef USE_LIB
  71.     /* 元の枝から曲がる角 */
  72.     arc_L = arc - (double)( ((rand() & 1)+ 1) * _PI / ((rand() & 1)+10) );
  73.     arc_R = arc + (double)( ((rand() & 1)+ 1) * _PI / ((rand() & 1)+10) );
  74.     
  75.     /* 枝の位置 */
  76.     x_L = x + len_L * sin( arc_L );
  77.     y_L = y - len_L * cos( arc_L );
  78.     x_R = x + len_R * sin( arc_R );
  79.     y_R = y - len_R * cos( arc_R );
  80.     
  81. #else
  82.     /* 元の枝から曲がる角 */
  83.     /* だいたい 11°~34°の範囲にあれば自然に見えるかな? */
  84.     arc_L = arc - (8 + (rand() & 0x0f));
  85.     arc_R = arc + (8 + (rand() & 0x0f));
  86.     arc_L &= 0xff;
  87.     arc_R &= 0xff;
  88.     
  89.     /* 枝の位置  256倍されているので256で割ること */
  90.     x_L = x + ((len_L * sin256( arc_L )) >>8 );
  91.     y_L = y - ((len_L * cos256( arc_L )) >>8 );
  92.     x_R = x + ((len_R * sin256( arc_R )) >>8 );
  93.     y_R = y - ((len_R * cos256( arc_R )) >>8 );
  94. #endif
  95.     
  96.     tree.n  = 3;
  97.     tree.x0 = x_L,    tree.y0 = y_L;
  98.     tree.x1 = x,    tree.y1 = y  ;
  99.     tree.x2 = x_R,    tree.y2 = y_R;
  100.     
  101.     EGB_penSize( EgbPtr, pen );
  102.     EGB_connect( EgbPtr, &tree );
  103.     
  104.     mk_treeLR( x_L, y_L, pen-1, len_L, arc_L );
  105.     mk_treeLR( x_R, y_R, pen-1, len_R, arc_R );
  106.     
  107. }
  108.  
  109.  
  110. void mk_treeFirst(x,y,pen,len)
  111. int     x,y,pen,len;
  112. {
  113.     int     ox,oy;
  114.     struct
  115.     {    short int n;
  116.         Rect    fr;
  117.     }connect;
  118.     
  119.     len *= 3;
  120.     ox = x;
  121.     oy = y-len;
  122.     
  123.     EGB_penSize( EgbPtr, pen+2 );
  124.     connect.n = 2;
  125.     SetRect( &connect.fr, x,y, ox,oy );
  126.     EGB_connect( EgbPtr, &connect );
  127.     
  128.     mk_treeLR( ox,oy, pen, len, 0 );
  129.     
  130. }
  131.  
  132. /********************************/
  133.  
  134. int APL_exec()
  135. {
  136.     int     x,y,pen,len;
  137.     
  138. //    clock_t    t;
  139. //    t=clock();
  140.     
  141.     
  142.     /* EGB_pset と同じ形式で値が入る */
  143.     x = WORD(g_para + 2);
  144.     y = WORD(g_para + 4);
  145.     
  146.     len  = cnfg[0].val * 2;        /* 高さ */
  147.     pen  = cnfg[1].val;            /* 太さ */
  148.     
  149.     
  150.     /* 描画ページの指定 */
  151.     EGB_writePage( EgbPtr, pi_imge->page );
  152.     
  153.     /* タイルパターンが選択されていたらそれを有効にする */
  154.     if( pi_data->til_mode )
  155.     {    EGB_tilePattern( EgbPtr, EGB_FORECOL,
  156.                     PI_TILE_X, PI_TILE_Y, PI_TILE_PAT );
  157.         EGB_paintMode( EgbPtr, EGB_PAINT_TILE );
  158.     }
  159.     else
  160.     {    EGB_color( EgbPtr, 0,  PI_FORECOL );
  161.         EGB_paintMode( EgbPtr, EGB_PAINT_BETA );
  162.     }
  163.     
  164.     /* ペン形状の指定 */
  165.     EGB_pen  ( EgbPtr, 1 );    /* 四角 */
  166.     
  167.     mk_treeFirst( x,y,pen,len );
  168.     
  169. //    printf("time = %d", clock()-t );
  170.     
  171.     /* スタンプ描画位置を返す */
  172.     ret_fr->lupx = x-stamp.x/2;
  173.     ret_fr->rdwx = x+stamp.x/2;
  174.     ret_fr->lupy = y-stamp.y/2;
  175.     ret_fr->rdwy = y+stamp.y/2;
  176.     
  177.     return NOERR;
  178. }
  179.  
  180. /**
  181.     速度比較
  182.             長6,太6        長10,太8
  183.     math        39            157
  184.     table        14             59
  185.     
  186. **/
  187.